/**
    算法描述：
    核心问题：
    解决所需数据结构+算法：
**/
#include<bits/stdc++.h>
using namespace std;
int f[1010] = {0};
 
int findfa(int x) {
    return f[x] = f[x] == x ? x : findfa(f[x]);
}
 
int main() {
    int n, m, ans = 1;
    scanf("%d%d", &n, &m);
    for (int i=1; i<=2*n; i++)
        f[i] = i;
    while(m--) {
        int x, y, lx, ly;
        char ch[2];
        scanf("%s%d%d", ch, &x, &y);
        if (ch[0] == 'E') {
            lx = findfa(x);
            ly = findfa(y+n);
            f[lx] = ly;
            lx = findfa(x+n);
            ly = findfa(y);
            f[lx] = ly;
        } else {
            lx = findfa(x);
            ly = findfa(y);
            f[lx] = ly;
            lx = findfa(x+n);
            ly = findfa(y+n);
            f[lx] = ly;
        }
    }
    for (int i=1; i<=2*n; i++)
        f[i] = findfa(i);
    sort(f+1, f+n+1);
    for (int i=2; i<=n; i++)
        if(f[i]!=f[i-1])
            ans++;
    printf("%d", ans);
    return 0;
}